import React from 'react';
import {Col, Row} from "antd";
import './index.less';
import Util from 'utils/utils';
import axios from 'service/Axios';

export default class Header extends React.Component{

    constructor(props) {
        super(props);

        this.state = {
            userName: '王小毛',
        };
    }

    componentWillMount() {

        setInterval(()=>{
            let sysTime = Util.formateDate(new Date().getTime());
            this.setState({
                sysTime
            });
        });

        this.getWeatherAPIData();
    }

    getWeatherAPIData = () => {
        let city = '110101';
        let outputType = 'json';
        let key = 'aed2bc3be0104a95842ab30fba3284c0';
        axios.jsonp({
            url: `https://restapi.amap.com/v3/weather/weatherInfo?key=${key}&city=${city}&output=${outputType}`,
        }).then((res) => {
            console.log('weather=',res);
            if (res.status === '1') {
                let data = res.lives[0];
                this.setState({
                    weather: data.weather
                })
            }
        }).then((err) => {
        });
    };


    render() {
        return (
            <div className="header">
                <Row className="header-top">
                    <Col span={24}>
                        <span>欢迎，{this.state.userName}</span>
                        <a href="jacascript::void(0);">退出</a>
                    </Col>
                </Row>
                <Row className="breadcrumb">
                    <Col span={4} className="breadcrumb-title">
                        首页
                    </Col>
                    <Col span={20} className="weather">
                        <span className="date">{this.state.sysTime}</span>
                        <span className="weather-detail">{this.state.weather}</span>
                    </Col>
                </Row>
            </div>
        );
    }

}